﻿// DetectorPluginsTest.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <Pluma/Pluma.hpp>
#include <iostream>
#include "../IDetetor.h"

#include <time.h>
#include<io.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <string>
#include "windows.h"
using std::string;

long long getSystemTime()
{
	struct timeb t;
	ftime(&t);
	return 1000 * t.time + t.millitm;
}

int main() {
    pluma::Pluma pluma;
    pluma.acceptProviderType<IDetetorProvider>();

	// Load libraries
#ifdef _DEBUG
	pluma.loadFromFolder("plugins");
#else 
	pluma.loadFromFolder("plugins");
#endif // DEBUG

    // Get warrior providers into a vector
    std::vector<IDetetorProvider*> providers;
    pluma.getProviders(providers);

    // Create a Warrior from each provider
    std::vector<IDetetorProvider*>::iterator it;
    for (it = providers.begin(); it != providers.end(); ++it) {
        // Create a warrior
        IDetetor* warrior = (*it)->create();
        // Display it's description
		if (warrior->getDescription() == "YOLO5")
		{
			std::cout << "确实" << std::endl;
			string model_path = "./model/yolov5x.onnx";//读取的模型
			warrior->readModel(model_path, true);
			vector<string> newClassName = { "cuppy", "hole", "ribbon", "dirt", "bubble", "stripe", "bubbel" };
			warrior->setClassName(newClassName);
			vector<Output> result;
			cv::Mat img = cv::imread("./images/3_8192.bmp");
			if (warrior->Detect(img, result)) {
				for (int i = 0; i < result.size(); i++)
				{
					char buffer[80];
					sprintf(buffer, "Result %d : class: %s,confidence :%f,x:%d,y:%d,w:%d,h:%d;", i, result[i].name.c_str(),result[i].confidence, result[i].box.x, result[i].box.y, result[i].box.width, result[i].box.height);
					string res_str = buffer;
					string res_str1 = result[i].name;
					OutputDebugStringA(res_str1.c_str());
					std::cout << "检测结果:"<<res_str<< std::endl;
					
				}
			}
			long long sta = getSystemTime();
			std::cout << "开始时间:" << sta << std::endl;
			for (int i = 0; i < 100; i++)
			{
				warrior->Detect(img, result);
			}
			long long sto = getSystemTime();
			std::cout << "结束时间:" << sto << std::endl;
			std::cout << "平均时间:" << (sto - sta) / 100 << std::endl;

		}
		if (warrior->getDescription() == "RCNN")
		{
			//std::cout << "就爱家哈就" << std::endl;
		}
        //warrior->readModel();
        // (...)
        // don't forget to delete it
        delete warrior;
    }
    pluma.unloadAll();
    std::cout << "Press any key to exit";
    std::cin.ignore(10000, '\n');
    return 0;
}

